package com.gomyb.redis.message;

import com.gomyb.redis.RedisService;
import com.gomyb.web.SpringContextUtil;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/6/13 18:01
 */
public class MessagePublish implements MessagePublisher {

    private String[] channel;

    public MessagePublish(String... channel) {
        this.channel = channel;
    }

    @Override
    public boolean sendMessage(String message) {
        try {
            RedisService redisService = SpringContextUtil.getBean("redisService");
            for (String cha : channel) {
                redisService.publish(cha, message);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
